<?php

namespace app\api\controller\wdsxh;

use app\admin\model\wdsxh\Config;
use app\admin\model\wdsxh\Faq as Model;

/**
 * 常见问题接口
 */
class Faq extends Base
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    public function lists()
    {
        $page = $this->request->param('page', 1);
        $limit = $this->request->param('limit', 10);
        $keywords = $this->request->param('keywords', null);
        $map = array(
            'status' => '1',
        );
        if (!empty($keywords)) {
            $map['title'] = ['like',"%{$keywords}%"];
        }

        $total = Model::where($map)->count();
        $list = Model::where($map)
            ->order('weigh desc')
            ->field('id,title,reply,createtime')
            ->page($page, $limit)
            ->select();
        if ($list) {
            foreach ($list as $row) {
                $row->createtime = date('Y-m-d H:i:s', $row->createtime);
            }
        }
        $data = array(
            'total' => $total,
            'list' => $list,
        );
        $this->success($data);
    }

    public function details(){
        $id = $this->request->param('id');
        $data = Model::where('id',$id)
            ->order('weigh desc')
            ->field('id,reply')
            ->find();
        $this->success($data);
    }

    public function qr_code(){
        $data = [
            'applet_code' =>wdsxh_full_url((new Config())->where('id',1)->value('applet_code')),
        ];
        $this->success('请求成功',$data);
    }
}
